#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 - 2013 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1

#include <Macros.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/Methods/Finitedifferences/TridiagonalOperator.h>
#pragma unmanaged 
#include <ql\methods\finitedifferences\dplus.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;
using namespace Cephei::Core;
using namespace PLATFORM::Collections;

using namespace Cephei::QL::Math;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Methods { namespace Finitedifferences {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IDPlus
	public ref class CDPlus  : 
            public CTridiagonalOperator,
            public Cephei::QL::Methods::Finitedifferences::IDPlus
	{
	protected: 
		boost::shared_ptr<QuantLib::DPlus>* _ppDPlus;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::DPlus>* _phDPlus;
#endif
		Object^ _DPlusOwner;     // reference to object that manages the storage for this object
	internal:
		CDPlus (UInt64 gridPoints, Double h);
        CDPlus (boost::shared_ptr<QuantLib::DPlus>& childNative, Object^ owner);
        CDPlus (QuantLib::DPlus& childNative, Object^ owner);
        CDPlus (CDPlus^ copy);
        CDPlus (PLATFORM::Type^ t);
#ifdef STRUCT
        CDPlus (QuantLib::DPlus childNative);
#endif       
#ifdef HANDLE
		CDPlus (QuantLib::Handle<QuantLib::DPlus>& childNative, Object^ owner);
		CDPlus (QuantLib::Handle<QuantLib::DPlus> childNative);
#endif
		virtual ~CDPlus ();
		!CDPlus ();

	internal:
		QuantLib::DPlus& GetReference ();
		boost::shared_ptr<QuantLib::DPlus>& GetShared ();
		QuantLib::DPlus* GetPointer ();
        void SetDPlus (boost::shared_ptr<QuantLib::DPlus> native)
        {
            if (_ppDPlus != NULL)
                delete _ppDPlus;
            _ppDPlus = new boost::shared_ptr<QuantLib::DPlus> (native);
            SetTridiagonalOperator (boost::dynamic_pointer_cast<QuantLib::TridiagonalOperator> (*_ppDPlus));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::DPlus>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
//z	[FactoryFor(Core::Generic::ICoCell<Cephei::QL::Methods::Finitedifferences::IDPlus^>::typeid)]
	[FactoryFor(Cephei::QL::Methods::Finitedifferences::IDPlus::typeid)]
	[FactoryFor(Cephei::QL::Methods::Finitedifferences::IDPlus_Factory::typeid)]
	public ref class CDPlus_Factory sealed : public IDPlus_Factory
	{
	public:
        virtual IDPlus^ Create (UInt64 gridPoints, Double h);
    };
   
/*Cephei*/ } /*QL*/ } /*Methods*/ } /*Finitedifferences */}
